import {getGoodsDetailApi} from '../../request/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goods_id:{},
    goodsObj:{},
  },
  GoodsInfo:{},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.goods_id =options;
  this.getDetailList()
  },
//  获取详情数据
 getDetailList(){
   getGoodsDetailApi(this.data.goods_id).then(res=>{
        console.log(res);
        this.setData({
          goodsObj:res.message,
        })
    })
  },
  handleImage(e){
   
/*     console.log(this.GoodsInfo.pics);
    const urls= this.GoodsInfo.pics.map(item=>item.pics_mid)
     const current=e.currentTarget.dataset.url
    wx-wx.previewImage({
      urls,
      current,
   
    }) */
  },
  handleCartAdd(){
    let cart=wx.getStorageSync('cart')||[]
  
    let index=cart.findIndex(item=>item.goods_id==this.data.goodsObj.goods_id)
    if(index===-1){
      this.data.goodsObj.num=1
      this.data.goodsObj.checked=true
    const a=  cart.push(this.data.goodsObj)
     console.log(a);
  }
  else{
      cart[index].num++
  }
  wx.setStorageSync('cart', cart)
     //弹窗提示
     wx.showToast({
      title: '加入成功',
      icon:'success',
      mask:true  //显示透明蒙层，防止触摸穿透
    })
  }
  
})